<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24" v-show="tabIndex === 0">
          <a-col :xl="8" :lg="11" :md="12" :sm="24">
            <a-form-item label="制单日期">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="unCreated_startTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="unCreated_startTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQueryUnCreated" icon="search">查询</a-button>
                  <a-button type="primary" @click="searchResetUnCreated" icon="reload" style="margin-left: 8px">重置</a-button>
                </span>
          </a-col>
        </a-row>
        <a-row :gutter="24" v-show="tabIndex === 4">
          <a-col :xl="8" :lg="11" :md="12" :sm="24">
            <a-form-item label="制单日期">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="startTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="startTime_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-show="tabIndex === 0" @click="handleAdd" type="primary" icon="plus">添加</a-button>
      <a-button v-show="tabIndex === 0" @click="reviewView" type="primary" icon="unordered-list">查看订单</a-button>
      <a-button @click="contractRequirementReview" type="primary" icon="unordered-list">查看合同要求评审表</a-button>
    </div>

    <div>
    <!-- table区域-begin -->
    <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
      <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
      <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      <span style="float:right;">
          <a-popover title="自定义列" trigger="click" placement="leftBottom">
            <template slot="content">
              <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                <a-row style="width: 400px">
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!=='rowIndex'&& item.dataIndex!=='action'">
                        <a-col :span="12"><a-checkbox :value="item.dataIndex"><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox></a-col>
                    </template>
                  </template>
                </a-row>
              </a-checkbox-group>
            </template>
            <a><a-icon type="setting" />设置</a >
          </a-popover>
        </span>
    </div>
      <a-tabs v-model="activeKey" @change="handleChangeTab">
        <a-tab-pane key="unCreated" tab="未生成">
          <div class="master-list">
            <!--<a-form layout="inline" @keyup.enter.native="searchQuery">
              <a-row :gutter="2">
                <a-col :xl="8" :lg="11" :md="12" :sm="24">
                  <a-form-item label="制单日期">
                    <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="unCreated_startTime_begin"></j-date>
                    <span class="query-group-split-cust"></span>
                    <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="unCreated_startTime_end"></j-date>
                  </a-form-item>
                </a-col>
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQueryUnCreated" icon="search">查询</a-button>
                </span>
                </a-col>
              </a-row>
            </a-form>-->
            <a-table
              ref="table"
              size="middle"
              bordered
              :rowKey="
                (record, index) => {
                  return record.id
                }
              "
              class="j-table-force-nowrap1"
              :scroll="{ x: true }"
              :columns="columns2"
              :dataSource="unCreatedTable.dataSource"
              :pagination="unCreatedTable.ipagination"
              :loading="unCreatedTable.loading"
              :rowSelection="{type: 'radio', selectedRowKeys: selectedRowKeysUncreated, onChange: onSelectChangeUncreated }"
              @change="handleTableChange1"
            >
            </a-table>
          </div>
          <div class="detail-list" v-if="selectedRowKeysUncreated.length > 0">
            <a-card title="物料配方明细" :bordered="false">
              <a-spin :spinning="detailLoading">
                <a-table
                  ref="detailTable"
                  size="middle"
                  bordered
                  rowKey="id"
                  :columns="detailColumns"
                  :dataSource="detailData"
                  :pagination="false"
                  :loading="detailLoading"
                  :rowSelection="{type: 'radio', selectedRowKeys: selectedDetailRowKeys, onChange: onSelectedDetailChange }"
                >
                </a-table>
              </a-spin>
            </a-card>
          </div>
        </a-tab-pane>
        <!--<a-tab-pane key="needEdit" tab="需修改">
          <a-table
            ref="needEditTable"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.id
              }
            "
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="needEditTable.dataSource"
            :pagination="needEditTable.ipagination"
            :loading="needEditTable.loading"
            :rowSelection="{type: 'radio', selectedRowKeys: selectedRowKeysNeedEdit, onChange: onSelectChangeNeedEdit }"
            @change="handleTableChange3"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a v-if="record.status < 0" @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical"></a-divider>
              <act-apply-btn
                v-show="record.status < 0"
                @success="loadTabData"
                :data-id="record.id"
                :serviceName="serviceName"
                :variables="record"
              ></act-apply-btn>
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>
        <a-tab-pane key="approving" tab="审批中">
          <a-table
            ref="approvingTable"
            size="middle"
            bordered
            rowKey="detailId"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="approvingTable.dataSource"
            :pagination="approvingTable.ipagination"
            :loading="approvingTable.loading"
            :rowSelection="{type: 'radio', selectedRowKeys: selectedRowKeysApproving, onChange: onSelectChangeApproving }"
            @change="handleTableChange4"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a v-if="record.actStatus != '撤回'" @click="handleStop(record)">取消申请</a>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>-->
        <a-tab-pane key="approved" tab="已审批">
          <!--<a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="2">
              <a-col :xl="8" :lg="11" :md="12" :sm="24">
                <a-form-item label="制单日期">
                  <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="startTime_begin"></j-date>
                  <span class="query-group-split-cust"></span>
                  <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="startTime_end"></j-date>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>-->
          <a-table
            ref="approvedTable"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.detailId
              }
            "
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="approvedTable.dataSource"
            :pagination="approvedTable.ipagination"
            :loading="approvedTable.loading"
            :rowSelection="{type: 'radio', selectedRowKeys: selectedRowKeysApproved, onChange: onSelectChangeApproved }"
            @change="handleTableChange5"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>
      </a-tabs>
    </div>
    <ips-pg-order-formula-modify-modal ref="modalForm" @ok="modalFormOk" />
    <!--<buss-hardware-procurementPlan-modal ref="procurementPlanModal" @ok="" />-->
    <buss-tra-orders-modal ref="reviewForm" @ok=""></buss-tra-orders-modal>
    <buss-contract-requirement-review-modal ref="contractRequirementReviewForm" @ok=""></buss-contract-requirement-review-modal>
  </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import IpsPgOrderFormulaModifyModal from './modules/IpsPgOrderFormulaModifyModal'
  import '@/assets/less/TableExpand.less'
  import moment from 'dayjs'
  import { getAction, getFileAccessHttpUrl, deleteAction, postAction } from '@api/manage'
  import ActApplyBtn from '@views/flowable/components/ActApplyBtn'
  import ActCancelBtn from '@views/flowable/components/ActCancelBtn'
  import ActHandleBtn from '@views/flowable/components/ActHandleBtn'
  import ActHistoricDetailBtn from '@views/flowable/components/ActHistoricDetailBtn'
  //import BussHardwareProcurementPlanModal from '../hardwareplan/modules/BussHardwareProcurementPlanModal'
  import BussTraOrdersModal from '@views/crm/tsldomestic/modules/BussTraOrdersModal'
  import BussContractRequirementReviewModal from '@views/crm/tsldomestic/modules/BussContractRequirementReviewModal'
  import {downFile} from "../../../api/manage";
  import { stopProcess } from '@/views/flowable/api/process'
  export default {
    name: 'IpsPgOrderFormulaModifyList',
    mixins: [JeecgListMixin],
    components: {
      IpsPgOrderFormulaModifyModal,
      ActApplyBtn,
      ActCancelBtn,
      ActHandleBtn,
      ActHistoricDetailBtn,
      //BussHardwareProcurementPlanModal,
      BussTraOrdersModal,
      BussContractRequirementReviewModal,
    },
    data() {
      return {
        description: 'TSL订单配方更改管理页面',
        moment,
        serviceName: 'tslOrderFormulaModifyService',
        activeKey: 'unCreated',
        startTime_begin: '',
        startTime_end: '',
        dateFormat: 'YYYY-MM-DD',
        tabIndex: 0,
        selectedRowKeysApproving: [],
        selectedRowKeysUncreated: [],
        selectedDetailRowKeys: [],
        selectionRowsApproving: [],
        selectionRowsUncreated: [],
        selectionDetailRows: [],
        selectedRowKeysApproved: [],
        selectedRowsApproved: [],
        selectedRowKeysNeedEdit: [],
        selectedRowsNeedEdit: [],
        unCreated_startTime_begin: moment().subtract(7, 'days').format('YYYY-MM-DD'),
        unCreated_startTime_end: moment().format('YYYY-MM-DD'),
        notGenerated_startTime_begin: moment().subtract(7, 'days').format('YYYY-MM-DD'),
        notGenerated_startTime_end: moment().format('YYYY-MM-DD'),
        sourceFrom: '2',
        unCreatedTable: {
          loading: false,
          dataSource: [],
          // 表头
          ipagination: {
            current: 1,
            pageSize: 30,
            pageSizeOptions: ['10', '20', '30'],
            showTotal: (total, range) => {
              return range[0] + '-' + range[1] + ' 共' + total + '条'
            },
            showQuickJumper: true,
            showSizeChanger: true,
            total: 0,
          },
        },
        notGeneratedTable: {
          loading: false,
          dataSource: [],
          // 表头
          ipagination: {
            current: 1,
            pageSize: 30,
            pageSizeOptions: ['10', '20', '30'],
            showTotal: (total, range) => {
              return range[0] + '-' + range[1] + ' 共' + total + '条'
            },
            showQuickJumper: true,
            showSizeChanger: true,
            total: 0,
          },
        },
        needEditTable: {
          loading: false,
          dataSource: [],
          // 表头
          ipagination: {
            current: 1,
            pageSize: 30,
            pageSizeOptions: ['10', '20', '30'],
            showTotal: (total, range) => {
              return range[0] + '-' + range[1] + ' 共' + total + '条'
            },
            showQuickJumper: true,
            showSizeChanger: true,
            total: 0,
          },
        },
        approvingTable: {
          loading: false,
          dataSource: [],
          // 表头
          ipagination: {
            current: 1,
            pageSize: 30,
            pageSizeOptions: ['10', '20', '30'],
            showTotal: (total, range) => {
              return range[0] + '-' + range[1] + ' 共' + total + '条'
            },
            showQuickJumper: true,
            showSizeChanger: true,
            total: 0,
          },
        },
        approvedTable: {
          loading: false,
          dataSource: [],
          // 表头
          ipagination: {
            current: 1,
            pageSize: 30,
            pageSizeOptions: ['10', '20', '30'],
            showTotal: (total, range) => {
              return range[0] + '-' + range[1] + ' 共' + total + '条'
            },
            showQuickJumper: true,
            showSizeChanger: true,
            total: 0,
          },
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '配方维护单号',
            align: 'center',
            dataIndex: 'code',
          },
          {
            title: '单据类型',
            align: 'center',
            dataIndex: 'documentType_dictText',
          },
          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'schedulingNumber',
          },
          {
            title: '合同评审单号',
            align: 'center',
            dataIndex: 'contractRequirementReviewCode',
          },
          {
            title: '客户名称',
            align: 'center',
            dataIndex: 'customerName',
          },
          {
            title: '订单年',
            align: 'center',
            dataIndex: 'year',
          },
          {
            title: '业务员',
            align: 'center',
            dataIndex: 'salesman_dictText',
          },
          {
            title: '物料名称',
            align: 'center',
            dataIndex: 'materialName',
          },
          {
            title: '规格型号',
            align: 'center',
            dataIndex: 'noneSpec',
          },
          /*{
            title: '配方通知单号',
            align: 'center',
            dataIndex: 'noticeNo',
          },*/
          {
            title: '配方号',
            align: 'center',
            dataIndex: 'formulaNumber',
          },
          {
            title: '配方名称',
            align: 'center',
            dataIndex: 'formulaDefine',
          },
          {
            title: '视比重',
            align: 'center',
            dataIndex: 'apparentProportion',
          },
          {
            title: '类型',
            align: 'center',
            dataIndex: 'formulaDesc_dictText',
          },
          {
            title: '配方类型',
            align: 'center',
            dataIndex: 'formulaType_dictText',
          },
          {
            title: '配方年',
            align: 'center',
            dataIndex: 'formulaYear',
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'createBy_dictText',
          },
          {
            title: '制单部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
          },
          {
            title: '制单日期',
            align: 'center',
            dataIndex: 'createTime',
            customRender: (text) => {
              if (!text) return '';
              return moment(text).format('YYYY-MM-DD');
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 150,
            scopedSlots: { customRender: 'action' },
          },
        ],
        settingColumns: [],
        defColumns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '配方维护单号',
            align: 'center',
            dataIndex: 'code',
          },
          {
            title: '单据类型',
            align: 'center',
            dataIndex: 'documentType_dictText',
          },
          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'schedulingNumber',
          },
          {
            title: '合同评审单号',
            align: 'center',
            dataIndex: 'contractRequirementReviewCode',
          },
          {
            title: '客户名称',
            align: 'center',
            dataIndex: 'customerName',
          },
          {
            title: '订单年',
            align: 'center',
            dataIndex: 'year',
          },
          {
            title: '业务员',
            align: 'center',
            dataIndex: 'salesman_dictText',
          },
          {
            title: '物料名称',
            align: 'center',
            dataIndex: 'materialName',
          },
          {
            title: '规格型号',
            align: 'center',
            dataIndex: 'noneSpec',
          },
          /*{
            title: '配方通知单号',
            align: 'center',
            dataIndex: 'noticeNo',
          },*/
          {
            title: '配方号',
            align: 'center',
            dataIndex: 'formulaNumber',
          },
          {
            title: '配方名称',
            align: 'center',
            dataIndex: 'formulaDefine',
          },
          {
            title: '视比重',
            align: 'center',
            dataIndex: 'apparentProportion',
          },
          {
            title: '类型',
            align: 'center',
            dataIndex: 'formulaDesc_dictText',
          },
          {
            title: '配方类型',
            align: 'center',
            dataIndex: 'formulaType_dictText',
          },
          {
            title: '配方年',
            align: 'center',
            dataIndex: 'formulaYear',
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'createBy_dictText',
          },
          {
            title: '制单部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
          },
          {
            title: '制单日期',
            align: 'center',
            dataIndex: 'createTime',
            customRender: (text) => {
              if (!text) return '';
              return moment(text).format('YYYY-MM-DD');
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 150,
            scopedSlots: { customRender: 'action' },
          },
        ],
        columns2: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '单据类型',
            align: 'center',
            dataIndex: 'documentType_dictText',
          },
          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'schedulingNumber',
          },
          {
            title: '合同评审单号',
            align: 'center',
            dataIndex: 'pssmCode',
          },
          {
            title: '客户名称',
            align: 'center',
            dataIndex: 'customerName',
          },
          {
            title: '订单年',
            align: 'center',
            dataIndex: 'year',
          },
          {
            title: '业务员',
            align: 'center',
            dataIndex: 'salesman_dictText',
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'createBy_dictText',
          },
          {
            title: '制单部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
          },
          {
            title: '制单日期',
            align: 'center',
            dataIndex: 'createTime',
            customRender: (text) => {
              if (!text) return '';
              return moment(text).format('YYYY-MM-DD');
            }
          },
        ],
        url: {
          list: '/ipspgorderformulamodify/ipsPgOrderFormulaModify/list',
          delete: '/ipspgorderformulamodify/ipsPgOrderFormulaModify/delete',
          deleteBatch: '/ipspgorderformulamodify/ipsPgOrderFormulaModify/deleteBatch',
          deleteDetail: '/ipspgorderformulamodify/ipsPgOrderFormulaModify/deleteDetail',
          exportXlsUrl: '/ipspgorderformulamodify/ipsPgOrderFormulaModify/exportXls',
          importExcelUrl: '/ipspgorderformulamodify/ipsPgOrderFormulaModify/importExcel',
          exportPlanXlsUrl: '/ipspgorderformulamodify/ipsPgOrderFormulaModify/exportXls',
        },
        dictOptions: {},
        superFieldList: [],
        // 子表数据
        detailData: [],
        detailLoading: false,
        // 子表列定义
        detailColumns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '物料名称',
            dataIndex: 'materialName',
            align: "center",
            width: 150
          },
          {
            title: '规格型号',
            dataIndex: 'noneSpec',
            align: "center",
            width: 150
          },
          {
            title: '配方号',
            dataIndex: 'formulaNumber',
            align: "center",
            width: 150
          },
          {
            title: '配方名称',
            dataIndex: 'formulaDefine',
            align: "center",
            width: 150
          },
          {
            title: '配方编码',
            dataIndex: 'formulaCode',
            align: "center",
            width: 150
          },
          {
            title: '视比重',
            dataIndex: 'apparentProportion',
            align: "center",
            width: 150
          },
          {
            title: '类型',
            dataIndex: 'formulaDesc_dictText',
            align: "center",
            width: 150
          },
          {
            title: '配方类型',
            dataIndex: 'formulaType_dictText',
            align: "center",
            width: 150
          },
          {
            title: '配方年',
            dataIndex: 'formulaYear',
            align: "center",
            width: 150
          },
        ],
      }
    },
    created() {
      this.sourceFrom = '2'
      this.getSuperFieldList()
      this.startTime_begin = moment().subtract(7, 'days').format(this.dateFormat)
      this.startTime_end = moment().format(this.dateFormat)
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      },
      curSelectedRowKeys: function () {
        if (this.tabIndex === 0) {
          return this.selectedRowKeysUncreated
        } else if (this.tabIndex === 1) {
          return this.selectedRowKeys
        } else if (this.tabIndex === 2) {
          return this.selectedRowKeysNeedEdit
        } else if (this.tabIndex === 3) {
          return this.selectedRowKeysApproving
        } else if (this.tabIndex === 4) {
          return this.selectedRowKeysApproved
        }
      },
    },
    methods: {
      initDictConfig() {},
      getSuperFieldList() {
        let fieldList = []
        fieldList.push({ type: 'string', value: 'code', text: '编号', dictCode: '' })
        this.superFieldList = fieldList
      },
      searchQuery() {
        this.loadApprovedData()
      },
      searchReset() {
        this.startTime_begin  = ''
        this.startTime_end  = ''
        this.loadApprovedData()
      },
      searchQueryUnCreated() {
        this.loadUnCreatedData()
      },
      searchResetUnCreated() {
        this.unCreated_startTime_begin = ''
        this.unCreated_startTime_end = ''
        this.loadUnCreatedData()
      },
      handleChangeTab() {
        switch (this.activeKey) {
          case 'unCreated':
            this.loadUnCreatedData()
            break
          case 'notGenerated':
            this.loadNotGeneratedData()
            break
          case 'needEdit':
            this.loadNeedEditData()
            break
          case 'approving':
            this.loadApprovingData()
            break
          case 'approved':
            this.loadApprovedData()
            break
          default:
            break
        }
      },
      loadUnCreatedData() {
        this.tabIndex = 0
        this.queryParam.status = 999
        this.queryParam.documentTypes = '3,4'
        this.queryParam.pageNo = this.unCreatedTable.ipagination.current;
        this.queryParam.pageSize = this.unCreatedTable.ipagination.pageSize;
        this.unCreatedTable.loading = true
        let para = {
          ...this.queryParam,
          createTimeBg: this.unCreated_startTime_begin ? this.unCreated_startTime_begin + ' 00:00:00' : '',
          createTimeEd: this.unCreated_startTime_end ? this.unCreated_startTime_end + ' 23:59:59' : '',
        }
        getAction('/review/crmTradeOrder/listOrderItems', para)
          .then((res) => {
            if (res.success) {
              this.unCreatedTable.dataSource = res.result.records || res.result
              if (res.result.total) {
                this.unCreatedTable.ipagination.total = res.result.total
              } else {
                this.unCreatedTable.ipagination.total = 0
              }
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.unCreatedTable.loading = false
          })
      },
      loadNotGeneratedData() {
        //暂存中，status=-2
        this.tabIndex = 1
        this.queryParam.status = -2
        this.queryParam.pageNo = this.notGeneratedTable.ipagination.current;
        this.queryParam.pageSize = this.notGeneratedTable.ipagination.pageSize;
        this.notGeneratedTable.loading = true
        let para = {
          ...this.queryParam,
          createTimeBg: this.notGenerated_startTime_begin + ' 00:00:00',
          createTimeEd: this.notGenerated_startTime_end + ' 23:59:59',
        }
        getAction(this.url.list, para)
          .then((res) => {
            if (res.success) {
              this.notGeneratedTable.dataSource = res.result.records || res.result
              if (res.result.total) {
                this.notGeneratedTable.ipagination.total = res.result.total
              } else {
                this.notGeneratedTable.ipagination.total = 0
              }
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.notGeneratedTable.loading = false
          })
      },
      //需修改
      loadNeedEditData() {
        //需修改单据，status=-1
        this.tabIndex = 2
        this.queryParam.status = -1
        this.queryParam.pageNo = this.needEditTable.ipagination.current;
        this.queryParam.pageSize = this.needEditTable.ipagination.pageSize;
        this.needEditTable.loading = true
        getAction(this.url.list, this.queryParam)
          .then((res) => {
            if (res.success) {
              this.needEditTable.dataSource = res.result.records || res.result
              if (res.result.total) {
                this.needEditTable.ipagination.total = res.result.total
              } else {
                this.needEditTable.ipagination.total = 0
              }
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.needEditTable.loading = false
          })
      },
      //审判中
      loadApprovingData() {
        //审核中单据，status=0
        this.tabIndex = 3
        this.queryParam.status = 0
        this.queryParam.pageNo = this.approvingTable.ipagination.current;
        this.queryParam.pageSize = this.approvingTable.ipagination.pageSize;
        this.approvingTable.loading = true
        getAction(this.url.list, this.queryParam)
          .then((res) => {
            if (res.success) {
              this.approvingTable.dataSource = res.result.records || res.result
              if (res.result.total) {
                this.approvingTable.ipagination.total = res.result.total
              } else {
                this.approvingTable.ipagination.total = 0
              }
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.approvingTable.loading = false
          })
      },
      //已审批
      loadApprovedData() {
        //已审核单据，status=999
        this.tabIndex = 4
        this.queryParam.status = 999
        this.queryParam.pageNo = this.approvedTable.ipagination.current;
        this.queryParam.pageSize = this.approvedTable.ipagination.pageSize;
        let para = {
          ...this.queryParam,
          createTimeBg: this.startTime_begin ? this.startTime_begin + ' 00:00:00' : '',
          createTimeEd: this.startTime_end ? this.startTime_end + ' 23:59:59' : '',
        }
        this.approvedTable.loading = true
        getAction(this.url.list, para)
          .then((res) => {
            if (res.success) {
              this.approvedTable.dataSource = res.result.records || res.result
              if (res.result.total) {
                this.approvedTable.ipagination.total = res.result.total
              } else {
                this.approvedTable.ipagination.total = 0
              }
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.approvedTable.loading = false
          })
      },
      async loadData() {
        //分别根据单据状态查询结果并将其放在
        this.queryParam = this.getQueryParams()
        this.loadUnCreatedData()
      },
      loadTabData() {
        const refreshMethod = this.getCurrentTabLoadMethod()
        refreshMethod()
      },
      onSelectChangeUncreated(selectedRowKeys, selectionRows) {
        this.selectedRowKeysUncreated = selectedRowKeys
        this.selectionRowsUncreated = selectionRows
        //子数据处理
        if (this.selectedRowKeysUncreated.length > 0) {
          this.loadDetailData(this.selectedRowKeysUncreated[0]);
        } else {
          this.detailData = [];
        }
      },
      onSelectedDetailChange(selectedRowKeys, selectionRows) {
        this.selectedDetailRowKeys = selectedRowKeys
        this.selectionDetailRows = selectionRows
      },
      loadDetailData(mainId) {
        this.detailLoading = true;
        this.detailData = [];
        getAction('/review/crmTradeOrder/listMaterialsItems', { mainId: mainId }).then(res => {
          if (res.success) {
            this.detailData = res.result;
          } else {
            this.$message.warning(res.message);
          }
        }).finally(() => {
          this.detailLoading = false;
        });
      },
      onSelectChangeApproving(selectedRowKeys, selectionRows) {
        this.selectedRowKeysApproving = selectedRowKeys
        this.selectionRowsApproving = selectionRows
      },
      onSelectChangeApproved(selectedRowKeys, selectionRows) {
        this.selectedRowKeysApproved = selectedRowKeys
        this.selectedRowsApproved = selectionRows
      },
      onSelectChangeNeedEdit(selectedRowKeys, selectionRows) {
        this.selectedRowKeysNeedEdit = selectedRowKeys
        this.selectedRowsNeedEdit = selectionRows
      },
      handleAdd: function () {
        if (this.selectionRowsUncreated.length <= 0 || this.selectionDetailRows.length <= 0) {
          this.$message.warning('请先选择订单和物料配方信息！')
          return
        }
        const ordrObj = this.selectionRowsUncreated[0];
        const materialObj = this.selectionDetailRows[0];
        this.$refs.modalForm.add(ordrObj, materialObj)
        this.$refs.modalForm.title = '新增'
        this.$refs.modalForm.disableSubmit = false
      },
      modalFormOk() {
        //刷新后 选中的记录清除
        this.$store.dispatch('savePurchasePlanDetailList', [])
        //this.loadNotGeneratedData()
        this.handleChangeTab()
        //清空列表选中
        this.onClearSelected()
      },
      reviewView() {
        if (this.selectedRowKeysUncreated.length <= 0 || this.selectedRowKeysUncreated.length > 1) {
          this.$message.warning('请选择订单记录！')
          return
        } else {
          this.$refs.reviewForm.edit(this.selectionRowsUncreated[0]);
          this.$refs.reviewForm.title = "详情";
          this.$refs.reviewForm.disableSubmit = true;
        }
      },
      contractRequirementReview(){
        let reviewId = '';
        if (this.tabIndex === 0) {
          if (this.selectedRowKeysUncreated.length <= 0 || this.selectedRowKeysUncreated.length > 1) {
            this.$message.warning('请选择订单记录！')
            return
          }
          reviewId = this.selectionRowsUncreated[0].reviewId;
        }
        if (this.tabIndex === 2) {
          if (this.selectedRowKeysNeedEdit.length <= 0  || this.selectedRowKeysNeedEdit.length > 1) {
            this.$message.warning('请选择订单记录！')
            return
          }
          reviewId = this.selectedRowsNeedEdit[0].reviewId;
        }
        if (this.tabIndex === 3) {
          if (this.selectedRowKeysApproving.length <= 0 || this.selectedRowKeysApproving.length > 1) {
            this.$message.warning('请选择订单记录！')
            return
          }
          reviewId = this.selectionRowsApproving[0].reviewId;
        }
        if (this.tabIndex === 4) {
          if (this.selectedRowKeysApproved.length <= 0 || this.selectedRowKeysApproved.length > 1) {
            this.$message.warning('请选择订单记录！')
            return
          }
          reviewId = this.selectedRowsApproved[0].reviewId;
        }
        getAction('/review/bussContractRequirementReview/getContractRequirementReview', { reviewId: reviewId }).then(res => {
          if (res.success) {
            this.$refs.contractRequirementReviewForm.edit(res.result)
            this.$refs.contractRequirementReviewForm.title = '详情'
            this.$refs.contractRequirementReviewForm.disableSubmit = true
          } else {
            this.$message.warning(res.message);
            return;
          }
        })
      },
      onClearSelected() {
        this.selectedRowKeysUncreated = [];
        this.selectionRowsUncreated = [];
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedRowKeysNeedEdit = [];
        this.selectedRowsNeedEdit = [];
        this.selectedRowKeysApproving = [];
        this.selectionRowsApproving = [];
        this.selectedRowKeysApproved = [];
        this.selectedRowsApproved = [];
      },
      getCurrentTabLoadMethod() {
        switch (this.activeKey) {
          case 'unCreated':
            return this.loadUnCreatedData;
          case 'notGenerated':
            return this.loadNotGeneratedData;
          case 'needEdit':
            return this.loadNeedEditData;
          case 'approving':
            return this.loadApprovingData;
          case 'approved':
            return this.loadApprovedData;
          default:
            return this.loadData;
        }
      },
      batchDelNotGenerated: function () {
        if (!this.url.deleteBatch) {
          this.$message.error('请设置url.deleteBatch属性!')
          return
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！')
          return
        } else {
          var ids = ''
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ','
          }
          var that = this
          this.$confirm({
            title: '确认删除',
            content: '是否删除选中数据?',
            onOk: function () {
              that.notGeneratedTable.loading = true
              deleteAction(that.url.deleteBatch, { ids: ids })
                .then((res) => {
                  if (res.success) {
                    //重新计算分页问题
                    that.reCalculatePage(that.selectedRowKeys.length)
                    that.$message.success(res.message)
                    /*that.loadNotGeneratedData()
                    that.onClearSelected()*/
                    const refreshMethod = that.getCurrentTabLoadMethod()
                    refreshMethod() // 执行当前Tab的刷新
                    that.onClearSelected()
                  } else {
                    that.$message.warning(res.message)
                  }
                })
                .finally(() => {
                  that.notGeneratedTable.loading = false
                })
            },
          })
        }
      },
      batchDelNeedEdit: function () {
        if (!this.url.deleteBatch) {
          this.$message.error('请设置url.deleteBatch属性!')
          return
        }
        if (this.selectedRowKeysNeedEdit.length <= 0) {
          this.$message.warning('请选择一条记录！')
          return
        } else {
          var ids = ''
          for (var a = 0; a < this.selectedRowKeysNeedEdit.length; a++) {
            ids += this.selectedRowKeysNeedEdit[a] + ','
          }
          var that = this
          this.$confirm({
            title: '确认删除',
            content: '是否删除选中数据?',
            onOk: function () {
              that.needEditTable.loading = true
              deleteAction(that.url.deleteBatch, { ids: ids })
                .then((res) => {
                  if (res.success) {
                    //重新计算分页问题
                    that.reCalculatePage(that.selectedRowKeysNeedEdit.length)
                    that.$message.success(res.message)
                    /*that.loadNotGeneratedData()
                    that.onClearSelected()*/
                    const refreshMethod = that.getCurrentTabLoadMethod()
                    refreshMethod() // 执行当前Tab的刷新
                    that.onClearSelected()
                  } else {
                    that.$message.warning(res.message)
                  }
                })
                .finally(() => {
                  that.needEditTable.loading = false
                })
            },
          })
        }
      },
      handleDelete: function (id) {
        if (!this.url.delete) {
          this.$message.error('请设置url.delete属性!')
          return
        }
        var that = this
        deleteAction(that.url.delete, { id: id }).then((res) => {
          if (res.success) {
            //重新计算分页问题
            that.reCalculatePage(1)
            const refreshMethod = that.getCurrentTabLoadMethod()
            refreshMethod() // 执行当前Tab的刷新
            that.$message.success(res.message)
            that.onClearSelected()
          } else {
            that.$message.warning(res.message)
          }
        })
      },
      handleStop(row) {
        const params = {
          instanceId: row.processInstanceId,
        }
        stopProcess(params).then((res) => {
          this.$message.success(res.message)
          const refreshMethod = this.getCurrentTabLoadMethod()
          refreshMethod()
          this.onClearSelected()
        })
      },
      handleJump() {
        if (this.selectedRowKeysApproved.length !== 1) {
          this.$message.warning('请选择一条记录！');
          return;
        }
        // 获取选中的记录
        const selectedRecord = this.approvedTable.dataSource.find(
          item => item.detailId === this.selectedRowKeysApproved[0]
        );
        // 设置 localStorage 标记
        localStorage.setItem('autoAddFunding', 'true');
        // 存储需要传递的参数
        localStorage.setItem('fundingParams', JSON.stringify({
          procurementCode: selectedRecord.code,
          documentType: '2',
          vendorName: selectedRecord.supplierName,
          procurementEnterprises: selectedRecord.purchaseCompany
        }));
        this.$router.push('/business/procurement/FundingApplicationList');
      },
      handleTableChange1(pagination, filters, sorter) {
        console.log(pagination)
        this.unCreatedTable.ipagination = pagination;
        this.loadUnCreatedData();
      },
      handleTableChange2(pagination, filters, sorter) {
        console.log(pagination)
        this.notGeneratedTable.ipagination = pagination;
        this.loadNotGeneratedData();
      },
      handleTableChange3(pagination, filters, sorter) {
        console.log(pagination)
        this.needEditTable.ipagination = pagination;
        this.loadNeedEditData();
      },
      handleTableChange4(pagination, filters, sorter) {
        console.log(pagination)
        this.approvingTable.ipagination = pagination;
        this.loadApprovingData();
      },
      handleTableChange5(pagination, filters, sorter) {
        console.log(pagination)
        this.approvedTable.ipagination = pagination;
        this.loadApprovedData();
      },
    },
  }
</script>
<style scoped>
  .master-list {
    margin-bottom: 20px;
  }

  .detail-list {
    flex: 1;
    overflow: auto;
  }
  @import '~@assets/less/common.less';
</style>
